import tools from '@/lib/tools';

class RemindStore {
  constructor() {
    // 存储已提醒过的更新内容
    /**
     * 存储格式
     *interface RemindData {
      [date: string]: [id:string][];
    }
     */

    this.storeKey = `advancedstockpool-detailsServicePack-${window.getUserid()}`;
  }
  get() {
    try {
      const res = localStorage.getItem(this.storeKey);
      return JSON.parse(res) || {};
    } catch (error) {
      tools.errorReport({
        name: `remindStore.js的get方法报错${error.name}`,
        message: error.message,
        stack: error.stack,
      });
    }
  }
  in(date, id) {
    const storeRes = this.get();
    return storeRes?.[date]?.includes(id + '');
  }
  push(date, id) {
    const storeRes = this.get();
    try {
      const dateArr = storeRes?.[date] || [];
      if (!dateArr.includes(id + '')) {
        dateArr.push(id + '');
      }
      storeRes[date] = dateArr;
      localStorage.setItem(this.storeKey, JSON.stringify(storeRes));
    } catch (error) {
      tools.errorReport({
        name: `remindStore.js的push方法报错${error.name}`,
        message: error.message,
        stack: error.stack,
      });
    }
  }
}
export default RemindStore;
